import 'package:flutter/material.dart';
import 'package:xws/helpers/safe_state.dart';
import 'package:xws/utils/app_util.dart';
import 'package:xws/utils/theme_util.dart';
import 'package:xws/utils/tools_util.dart';
import 'package:xws/widgets/app_btn.dart';

/// 升级弹框
class LvUp extends StatefulWidget {
  const LvUp({
    Key? key,
    required this.newLevel,
    required this.currPoints,
  }) : super(key: key);

  @override
  _LvUpState createState() => _LvUpState();

  final int newLevel;
  final int currPoints;
}

class _LvUpState extends State<LvUp> with SafeState<LvUp> {
  double _scale = 0;

  @override
  void initState() {
    super.initState();
    delayed(const Duration(milliseconds: 100)).then((_) {
      safeSetState(() => _scale = 1);
    });
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedScale(
      scale: _scale,
      duration: const Duration(milliseconds: 500),
      curve: Curves.elasticOut,
      child: Container(
        width: 300,
        height: 360,
        child: Column(
          children: <Widget>[
            const Text('恭喜您等级提升至', style: TextStyle(fontSize: 16)),
            const SizedBox(height: 20),
            Text(
              'Lv.${widget.newLevel}',
              style: TextStyle(
                fontSize: 40,
                fontWeight: FontWeight.w900,
                color: theme(context),
              ),
            ),
            const SizedBox(height: 20),
            Text('当前积分 ${widget.currPoints}', style: const TextStyle(fontSize: 14)),
            const Spacer(),
            AppBtn(
              onTap: () => close(context),
              text: '确定',
              height: 46,
              radius: 10,
              alignment: Alignment.center,
            ),
          ],
        ),
        padding: const EdgeInsets.all(30),
        decoration: BoxDecoration(
          color: white(context),
          borderRadius: BorderRadius.circular(20),
        ),
      ),
    );
  }
}
